package org.example.myleet.p704;

public class Solution {
    public int search(int[] nums, int target) {
        int l = 0, r = nums.length - 1, m;
        while (r - l > 1) {
            m = (l + r) / 2;
            if (nums[m] > target) {
                r = m;
            } else if (nums[m] < target) {
                l = m;
            } else {
                return m;
            }
        }
        if (nums[l] == target) {
            return l;
        }
        if (nums[r] == target) {
            return r;
        }
        return -1;
    }
}
